<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp();
    // 定义混入对象
    const mixin = {
      data(){
        return {
          msg: '混入上的数据'
        }
      },
      methods: {
        changeMsg() {
          this.msg = '值改变了'
        }
      },
      computed: {
        reverseMsg(){
          return this.msg.split('').reverse().join('');
        }
      }
    }
    const CommonHead =  {
      template: `
        <div>
          <h2>公共头部组件</h2>  
          <button @click="changeMsg">修改msg</button>
          {{ msg }}
          <br/>
          {{ reverseMsg }}
        </div>
      `,
      data(){
        return {
          msg: '这是自己的数据'
        }
      },
      mixins: [mixin]
    }
    app.component('CommonHead', CommonHead)

    app.mount('#app')
  </script>
</body>
</html>